#include "events.h"

void event_loop() {
    int quit = 0;
    SDL_Event event;
    while (!quit) {
        while (SDL_PollEvent(&event)) { /* Loop until there are no events left on the queue */
            switch (event.type) { /* Process the appropiate event type */
            case SDL_ACTIVEEVENT:
                if (event.active.state & SDL_APPMOUSEFOCUS) {
                    if (event.active.gain) {
                        printf("Mouse focus gained\n");
                    } else {
                        printf("Mouse focus lost\n");
                    }
                }
                if (event.active.state & SDL_APPINPUTFOCUS) {
                    if (event.active.gain) {
                        printf("Input focus gained\n");
                    } else {
                        printf("Input focus lost\n");
                    }
                }
                if (event.active.state & SDL_APPACTIVE) {
                    if (event.active.gain) {
                        printf("Application restored\n");
                    } else {
                        printf("Application iconified\n");
                    }
                }
                break;
            case SDL_KEYDOWN:  /* Handle a KEYDOWN event */
                printf("Key pressed:\n");
                printf("       SDL sim: %i\n",event.key.keysym.sym);
                printf("       modifiers: %i\n",event.key.keysym.mod);
                printf("       unicode: %i (if enabled with SDL_EnableUNICODE)\n",\
                       event.key.keysym.unicode);
                break;
            case SDL_KEYUP:
                printf("Key released:\n");
                printf("       SDL sim: %i\n",event.key.keysym.sym);
                printf("       modifiers: %i\n",event.key.keysym.mod);
                printf("       unicode: %i (if enabled with SDL_EnableUNICODE)\n",\
                       event.key.keysym.unicode);
                break;
            case SDL_MOUSEMOTION:
                printf("Mouse moved to: (%i,%i) ", event.motion.x, event.motion.y);
                printf("change: (%i,%i)\n", event.motion.xrel, event.motion.yrel);
                printf("       button state: %i\n",event.motion.state);
                break;
            case SDL_MOUSEBUTTONDOWN:
                printf("Mouse button %i ",event.button.button);
                printf("pressed with mouse at (%i,%i)\n",event.button.x,event.button.y);
                break;
            case SDL_MOUSEBUTTONUP:
                printf("Mouse button %i ",event.button.button);
                printf("released with mouse at (%i,%i)\n",event.button.x,event.button.y);
                break;
            case SDL_VIDEORESIZE:
                printf("Window resized to: (%i,%i)\n",event.resize.w, event.resize.h);
                break;
            case SDL_VIDEOEXPOSE:
                printf("Window exposed\n");
                break;
            case SDL_QUIT:
                printf("Request to quit\n");
                quit = 1;
                break;
            case SDL_USEREVENT:
                printf("User event:\n");
                printf("       code:  %i\n",event.user.code);
                printf("       data1: %p\n",event.user.data1);
                printf("       data2: %p\n",event.user.data2);
                break;
            case SDL_SYSWMEVENT:
                printf("Window manager event\n");
                break;
            default: /* Report an unhandled event */
                printf("I don't know what this event is!\n");
            }
        }
    }
}
